# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python


class Recipe(recipe.Recipe):
    name = 'cmake'
    version = '3.7.1'
    licenses = [License.BSD_like]
    btype = BuildType.MAKEFILE
    stype = SourceType.TARBALL
    url = 'http://www.cmake.org/files/v3.7/cmake-3.7.1.tar.gz'
    deps = ['autoconf']

    add_host_build_target = False
    config_sh = './bootstrap'
    configure_tpl = "%(config-sh)s --prefix=%(prefix)s"
    can_use_configure_cache = False

    files_bins = ['cmake', 'ccmake']

    def prepare(self):
        if self.config.target_platform == Platform.WINDOWS:
            if self.config.target_arch == Architecture.X86_64:
                # Setting SYSTEM_NAME sets CMAKE_CROSSCOMPILING and the
                # binutils such as ar and ranlib are prefixed correctly
                self.configure_tpl += ' -- -DCMAKE_SYSTEM_NAME="Windows"'

    def configure(self):
        if self.config.target_platform == Platform.WINDOWS:
            if self.config.target_arch == Architecture.X86_64:
                # Bootstrap needs to be run twice for some dark reason
                try:
                    super(recipe.Recipe, self).configure()
                except:
                    pass
        super(recipe.Recipe, self).configure()
        # Windows XP does not have _mkgmtime64
        shell.replace(os.path.join(self.build_dir, 'CMakeCache.txt'),
            {'HAVE__MKGMTIME64:INTERNAL=1':'HAVE__MKGMTIME64:INTERNAL='})
